package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.ConfirmGoodBeen;

/**
 * @author gzk
 * @date 2020/3/28 0028
 * description：时间段选择
 */
public class SelectTimeLVAdapter extends BaseAdapter {

    private Context mContext;
    private List<ConfirmGoodBeen.DataBean.DeliveryTimeListBean.SameDayBean> mList;

    private TextView tv_select_time;
    private ImageView iv_select_time_dui;
    public int now_position;
    private boolean isShow=true;

    public SelectTimeLVAdapter(Context mContext, List<ConfirmGoodBeen.DataBean.DeliveryTimeListBean.SameDayBean> mList) {
        this.mContext = mContext;
        this.mList = mList;

    }

    public void setData(List<ConfirmGoodBeen.DataBean.DeliveryTimeListBean.SameDayBean> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    public void setItem(boolean isShow,int now_position){
        this.isShow=isShow;
        this.now_position=now_position;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        view = View.inflate(mContext, R.layout.item_select_time, null);
        tv_select_time = view.findViewById(R.id.tv_select_time);
        iv_select_time_dui = view.findViewById(R.id.iv_select_time_dui);

        tv_select_time.setText(mList.get(i).getDeliveryTime());
        if (isShow){
            if (i == now_position) {
                tv_select_time.setTextColor(mContext.getResources().getColor(R.color.color_02C557));
                iv_select_time_dui.setVisibility(View.VISIBLE);
            } else {
                tv_select_time.setTextColor(mContext.getResources().getColor(R.color.color_333333));
                iv_select_time_dui.setVisibility(View.GONE);
            }
        }else {
            tv_select_time.setTextColor(mContext.getResources().getColor(R.color.color_333333));
            iv_select_time_dui.setVisibility(View.GONE);
        }



        return view;
    }
}
